package cn.edu.pet.repo;

import cn.edu.pet.db.BaseRepo;
import cn.edu.pet.db.ResultSetVisitor;
import cn.edu.pet.entity.Admin;

import java.sql.ResultSet;
import java.sql.SQLException;

public class AdminRepo extends BaseRepo {
    private static AdminRepo instance = new AdminRepo();

    public static AdminRepo getInstance() {
        return instance;
    }

    private AdminRepo() {
    }

    public Admin getByName(String name) throws SQLException {
        String sql = String.format("select * from admin where username = %s", name);
        Admin admin = new Admin();
        this.query(sql, resultSet -> {
            try {
                admin.setId(resultSet.getInt(1));
                admin.setUsername(resultSet.getString(2));
                admin.setPassword(resultSet.getString(3));
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        });
        return admin;
    }
}
